package com.fysports.web.module.view.vo;

import com.jfinal.core.Controller;
import com.fysports.framework.kit.sql.Conditions;
import com.fysports.web.kit.commons.StringKit;

import java.util.Map;


/**
 * 页面VO实现类别，有常用操作
 * //TODO comment
 * Date : 14-9-16 下午9:06
 * Project : JdmData_WebServer
 */
public class BaseWebVO extends AbstractBaseWebVO implements IBaseVO {
    /* 分页参数：p */
    public int pageIndex;


    public BaseWebVO() {
    }


    public BaseWebVO(Controller ctr) {
        pageIndex = ctr.getParaToInt("p", 1);
        initParamsReq(ctr);
    }


    @Override public void initParamsReq(Controller ctr) {
    }


    @Override public Conditions getConditions() {
        return new Conditions();
    }


    @Override public Map<String, Object> getParamsMap() {
        return null;
    }


    @Override public void setQueryData(Controller ctr) {

    }


    public int getPageIndex() {
        return pageIndex;
    }


    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }


    @Override public String toParams() {
        return "?p=" + pageIndex;
    }


    /**
     * 用于中文字符串的编码
     *
     * @param str
     * @return
     */
    public String encode(String str) {
        String result = "";
        if (StringKit.notBlank(str)) {
            try {
                result = StringKit.encode(str);
            }
            catch (Exception e) {
                e.printStackTrace();
                result = str;
            }
        }
        return result;
    }


    /**
     * 用于中文字符串的解码
     *
     * @param str
     * @return
     */
    public String decode(String str) {
        String result = "";
        if (StringKit.notBlank(str)) {
            try {
                result = StringKit.decode(str);
            }
            catch (Exception e) {
                e.printStackTrace();
                result = str;
            }
        }
        return result;
    }
}
